package org.teststack.Test123;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;


public class Sjqd {

    public static void main(String[] args) {
        testApiWithDataDriven();
    }


        // Excel文件路径（根据实际情况修改）
        private static final String EXCEL_FILE_PATH = "D:\\1\\数据.xlsx";

    private static Iterator<String> readIdsFromExcel() {
        List<String> ids = new ArrayList<>();
        try (FileInputStream fis = new FileInputStream(new File(EXCEL_FILE_PATH));
             Workbook workbook = new XSSFWorkbook(fis)) {

            Sheet sheet = workbook.getSheetAt(0); // 假设数据在第一个工作表上
            Iterator<Row> rowIterator = sheet.iterator();

            // 跳过标题行（如果有的话）
            if (rowIterator.hasNext()) {
                rowIterator.next();
            }

            while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                Cell idCell = row.getCell(0); // 假设id在第一列
                if (idCell != null && idCell.getCellType() == CellType.STRING) {
                    ids.add(idCell.getStringCellValue());
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
            // 可以选择抛出异常或返回空迭代器
            return Collections.emptyIterator();
        }
        return ids.iterator();
    }

    // 测试方法
    public static void testApiWithDataDriven() {
        Iterator<String> idIterator = readIdsFromExcel();

        while (idIterator.hasNext()) {
            String id = idIterator.next();
            System.out.println(id);
//            // 使用Rest-Assured调用API
//            Response response = RestAssured.given()
//                    .param("id", id)
//                    .when()
//                    .get("/your-api-endpoint");

            // 添加断言来验证响应
            // ...
        }

    }}
